package com.jack.leetcode.eachproblem_2020;

import org.apache.commons.lang3.builder.HashCodeBuilder;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

/**
 * Created by zhang_j on 2020/11/17
 */
public class 距离顺序排列矩阵单元格 {

    static class Num{
        int l;
        int r;

        public int getL() {
            return l;
        }

        public void setL(int l) {
            this.l = l;
        }

        public int getR() {
            return r;
        }

        public void setR(int r) {
            this.r = r;
        }

        public Num(int l, int r){
            this.l = l;
            this.r = r;
        }

        @Override
        public boolean equals(Object obj) {
            Num ob = (Num) obj;
            return this.l == ob.l && this.r == ob.r;
        }

        @Override
        public int hashCode() {
            return new HashCodeBuilder(17, 37)
                    .append(l)
                    .append(r)
                    .toHashCode();
        }
    }

    public static void main(String[] args) {
        allCellsDistOrder(1,2,0,0);
    }

    public static int[][] allCellsDistOrder(int R, int C, int r0, int c0) {
        int max = 0;

        for(int l = 0;l < R;l++){
            for(int r = 0;r < C;r++){
                max = Math.max(max, Math.abs(l - r0) + Math.abs(r - c0));
            }
        }

        int[][] result = new int[R * C][2];
        int index = 0;
        for(int i = 0;i <= max;i++){
            for(int l = 0;l < R;l++){
                for(int r = 0;r < C;r++){
                    if(Math.abs(l - r0) + Math.abs(r - c0) == i){
                        result[index][0] = l;
                        result[index++][1] = r;
                    }
                }
            }
        }
        return result;
    }

    private static boolean isValid(int l, int r, int R, int C){
        return l >= 0 && r >= 0
                && l < R && r < C;
    }
}
